﻿package mortal.game.scene3D.ai.ais
{
    import Message.Game.*;
    import Message.Public.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.ai.*;
    import mortal.game.scene3D.ai.base.*;
    import mortal.game.scene3D.layer3D.utils.*;
    import mortal.game.scene3D.map3D.sceneInfo.*;
    import mortal.game.scene3D.map3D.util.*;
    import mortal.game.utils.*;
    import mortal.mvc.core.*;

    public class PassAI extends AICommand
    {
        public static const EnterGuildType:int = -123451;

        public function PassAI()
        {
            return;
        }// end function

        override public function start(param1:Function = null) : void
        {
            var _loc_4:int = 0;
            var _loc_5:SceneInfo = null;
            super.start(param1);
            var _loc_2:* = data.params as SPassPoint;
            if (_loc_2 == null)
            {
                this.stop();
                return;
            }
            if (_loc_2.type == EnterGuildType)
            {
                GameProxy.copy.enterGuildManor(_loc_2.mapId);
                Dispatcher.addEventListener(EventName.Scene_Update, this.mapSwitchedHandler);
                return;
            }
            var _loc_3:* = _loc_2.passTo[0] as SPassTo;
            if (GameMapUtil.curMapState.isTowerMap)
            {
                _loc_4 = Cache.instance.copy.copyInfo.code;
                if (Cache.instance.copy.tower.getHasFinishAllPass(_loc_4))
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.CopyLeave));
                }
                else if (GameController.copy.towerCopy.allowPassTo)
                {
                    AIManager.cancelAll();
                    Dispatcher.dispatchEvent(new DataEvent(EventName.AutoGuideEnterCopyAutoFight));
                    GameProxy.tower.enterTowerCopy(_loc_4, Cache.instance.copy.tower.getCurrentLevel(_loc_4));
                }
                else
                {
                    this.stop();
                    return;
                }
            }
            else if (GameMapUtil.curMapState.isGroupTowerMap)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.CopyLeave));
            }
            else if (_loc_3 == null || _loc_3.toPoint == null)
            {
                if (Cache.instance.copy.isInCopy && !Cache.instance.guild.isInGuild)
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.CopyClickQuickBtn));
                }
                else
                {
                    GameProxy.copy.leaveCopy();
                }
            }
            else if (PassUtil.isPassToSameServerBossHodType(_loc_3))
            {
                CopyUtil.copyCheck(this.passToSameServerBossHoldType, _loc_3);
            }
            else if (PassUtil.isPassToCopyType(_loc_3))
            {
                CopyUtil.copyCheck(this.passToLocalCopyType, _loc_3);
            }
            else if (PassUtil.isPassToCrossServerMapType(_loc_3))
            {
                _loc_5 = SceneConfig.instance.getSceneInfo(_loc_3.mapId);
                GameProxy.copy.enterCrossServerMap(_loc_5.sMapDefine.needLevel);
            }
            else if (PassUtil.isPassToCrossBossHodType(_loc_3))
            {
                CopyUtil.copyCheck(this.passToCopyType, _loc_3, _loc_2);
            }
            else if (PassUtil.isPassToCrossMainCity(_loc_3))
            {
                CopyUtil.copyCheck(this.passToCrossMainCity, _loc_3, _loc_2);
            }
            else
            {
                GameProxy.sceneProxy.pass(new EPassType(EPassType._EPassTypePassPoint), _loc_2.passPointId, _loc_3.passToId, _loc_3.toPoint);
            }
            Dispatcher.addEventListener(EventName.Scene_Update, this.mapSwitchedHandler);
            return;
        }// end function

        private function passToSameServerBossHoldType(param1:SPassTo) : void
        {
            GameProxy.copy.enterLocalHoleCopy(param1.mapId);
            return;
        }// end function

        private function passToLocalCopyType(param1:SPassTo) : void
        {
            GameProxy.copy.enterCopy(param1.mapId);
            return;
        }// end function

        private function passToCopyType(param1:SPassTo, param2:SPassPoint) : void
        {
            GameProxy.sceneProxy.pass(new EPassType(EPassType._EPassTypePassPoint), param2.passPointId, param1.passToId, param1.toPoint);
            return;
        }// end function

        private function passToCrossMainCity(param1:SPassTo, param2:SPassPoint) : void
        {
            GameProxy.copy.enterCrossMainCity();
            return;
        }// end function

        private function mapSwitchedHandler(event:DataEvent) : void
        {
            this.stop();
            return;
        }// end function

        override public function stop(param1:Boolean = true) : void
        {
            super.stop(param1);
            Dispatcher.removeEventListener(EventName.Scene_Update, this.mapSwitchedHandler);
            return;
        }// end function

    }
}
